package com.zxy.broker.controller;

import java.util.Arrays;
import java.util.Map;


import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import com.zxy.broker.entity.HousesEntity;
import com.zxy.broker.service.HousesService;
import com.zxy.common.utils.PageUtils;
import com.zxy.common.utils.R;



/**
 * 楼盘
 *
 * @author axy
 * @email sunlightcs@gmail.com
 * @date 2022-04-27 18:48:51
 */
@RestController
@RequestMapping("broker/houses")
@CrossOrigin
public class HousesController {
    @Autowired
    private HousesService housesService;
    @Autowired
    RabbitTemplate rabbitTemplate;

    /**
     * 列表
     */
    @RequestMapping("/list")

    public R list(@RequestParam Map<String, Object> params){
        PageUtils page = housesService.queryPage(params);

        return R.ok().put("page", page);
    }
    @RequestMapping("/eslist")

    public R eslist(@RequestParam Map<String, Object> params){
        PageUtils page = housesService.eslist(params);

        return R.ok().put("page", page);
    }

    /**
     * 信息
     */
    @RequestMapping("/info/{id}")

    public R info(@PathVariable("id") Long id){
		HousesEntity houses = housesService.getById(id);

        return R.ok().put("houses", houses);
    }

    /**
     * 保存
     */
    @RequestMapping("/save")

    public R save(@RequestBody HousesEntity houses){
		housesService.save(houses);
		rabbitTemplate.convertAndSend("bw1","新增楼盘完成");
        System.out.println("新增楼盘完成");
        return R.ok();
    }

    /**
     * 修改
     */
    @RequestMapping("/update")
    public R update(@RequestBody HousesEntity houses){
		housesService.updateById(houses);

        return R.ok();
    }

    /**
     * 删除
     */
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] ids){
		housesService.removeByIds(Arrays.asList(ids));

        return R.ok();
    }


    //单删
    @RequestMapping("/delete/{id}")
    public R delete(@PathVariable("id")Integer id){
        housesService.removeById(id);

        return R.ok();
    }

}
